﻿// Copyright (C) Norsolutions GmbH
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Reng van Oord
// Created:    2010.05.05


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sherwood.Mvc.Html
{
    /// <summary>
    /// Provides a culture list source for an ASP.Net MVC drop down list.
    /// Value is the .Net culture code and text is the name in English.
    /// </summary>
    public class CultureSelectList
    {
        public static List<SelectListItem> GetList(object selectedValue, bool translate)
        {
            if (selectedValue == null)
            {
                selectedValue = "en-US";
            }
            string[] values = new string[] { 
"af-ZA","Afrikaans - South Africa",
"sq-AL","Albanian - Albania",
"ar-DZ","Arabic - Algeria",
"ar-BH","Arabic - Bahrain",
"ar-EG","Arabic - Egypt",
"ar-IQ","Arabic - Iraq",
"ar-JO","Arabic - Jordan",
"ar-KW","Arabic - Kuwait",
"ar-LB","Arabic - Lebanon",
"ar-LY","Arabic - Libya",
"ar-MA","Arabic - Morocco",
"ar-OM","Arabic - Oman",
"ar-QA","Arabic - Qatar",
"ar-SA","Arabic - Saudi Arabia",
"ar-SY","Arabic - Syria",
"ar-TN","Arabic - Tunisia",
"ar-AE","Arabic - United Arab Emirates",
"ar-YE","Arabic - Yemen",
"hy-AM","Armenian - Armenia",
"az-Cyrl-AZ","Azeri (Cyrillic) - Azerbaijan",
"az-Latn-AZ","Azeri (Latin) - Azerbaijan",
"eu-ES","Basque - Basque",
"be-BY","Belarusian - Belarus",
"bg-BG","Bulgarian - Bulgaria",
"ca-ES","Catalan - Catalan",
"zh-HK","Chinese - Hong Kong SAR (Traditional)",
"zh-MO","Chinese - Macau SAR (Traditional)",
"zh-CN","Chinese - China (Simplified)",
"zh-SG","Chinese - Singapore (Simplified)",
"zh-TW","Chinese - Taiwan (Traditional)",
"hr-HR","Croatian - Croatia",
"cs-CZ","Czech - Czech Republic",
"da-DK","Danish - Denmark",
"nl-BE","Dutch - Belgium",
"nl-NL","Dutch - The Netherlands",
"en-AU","English - Australia",
"en-BZ","English - Belize",
"en-CA","English - Canada",
"en-CB","English - Caribbean",
"en-IE","English - Ireland",
"en-JM","English - Jamaica",
"en-NZ","English - New Zealand",
"en-PH","English - Philippines",
"en-ZA","English - South Africa",
"en-TT","English - Trinidad and Tobago",
"en-GB","English - United Kingdom",
"en-US","English - United States",
"en-ZW","English - Zimbabwe",
"et-EE","Estonian - Estonia",
"fo-FO","Faroese - Faroe Islands",
"fa-IR","Farsi - Iran",
"fi-FI","Finnish - Finland",
"fr-BE","French - Belgium",
"fr-CA","French - Canada",
"fr-FR","French - France",
"fr-LU","French - Luxembourg",
"fr-MC","French - Monaco",
"fr-CH","French - Switzerland",
"gl-ES","Galician - Galician",
"ka-GE","Georgian - Georgia",
"de-AT","German - Austria",
"de-DE","German - Germany",
"de-LI","German - Liechtenstein",
"de-LU","German - Luxembourg",
"de-CH","German - Switzerland",
"el-GR","Greek - Greece",
"gu-IN","Gujarati - India",
"he-IL","Hebrew - Israel",
"hi-IN","Hindi - India",
"hu-HU","Hungarian - Hungary",
"is-IS","Icelandic - Iceland",
"id-ID","Indonesian - Indonesia",
"it-IT","Italian - Italy",
"it-CH","Italian - Switzerland",
"ja-JP","Japanese - Japan",
"kn-IN","Kannada - India",
"kk-KZ","Kazakh - Kazakhstan",
"kok-IN","Konkani - India",
"ko-KR","Korean - Korea",
"ky-KG","Kyrgyz - Kazakhstan",
"lv-LV","Latvian - Latvia",
"lt-LT","Lithuanian - Lithuania",
"mk-MK","Macedonian - FYROM",
"ms-BN","Malay - Brunei",
"ms-MY","Malay - Malaysia",
"mr-IN","Marathi - India",
"mn-MN","Mongolian - Mongolia",
"nb-NO","Norwegian (Bokmål) - Norway",
"nn-NO","Norwegian (Nynorsk) - Norway",
"pl-PL","Polish - Poland",
"pt-BR","Portuguese - Brazil",
"pt-PT","Portuguese - Portugal",
"pa-IN","Punjabi - India",
"ro-RO","Romanian - Romania",
"ru-RU","Russian - Russia",
"sa-IN","Sanskrit - India",
"sr-Cyrl-RS","Serbian (Cyrillic) - Serbia",
"sr-Latn-RS","Serbian (Latin) - Serbia",
"sk-SK","Slovak - Slovakia",
"sl-SI","Slovenian - Slovenia",
"es-AR","Spanish - Argentina",
"es-BO","Spanish - Bolivia",
"es-CL","Spanish - Chile",
"es-CO","Spanish - Colombia",
"es-CR","Spanish - Costa Rica",
"es-DO","Spanish - Dominican Republic",
"es-EC","Spanish - Ecuador",
"es-SV","Spanish - El Salvador",
"es-GT","Spanish - Guatemala",
"es-HN","Spanish - Honduras",
"es-MX","Spanish - Mexico",
"es-NI","Spanish - Nicaragua",
"es-PA","Spanish - Panama",
"es-PY","Spanish - Paraguay",
"es-PE","Spanish - Peru",
"es-PR","Spanish - Puerto Rico",
"es-ES","Spanish - Spain",
"es-UY","Spanish - Uruguay",
"es-VE","Spanish - Venezuela",
"sw-KE","Swahili - Kenya",
"sv-FI","Swedish - Finland",
"sv-SE","Swedish - Sweden",
"syr-SY","Syriac - Syria",
"ta-IN","Tamil - India",
"tt-RU","Tatar - Russia",
"te-IN","Telugu - India",
"th-TH","Thai - Thailand",
"tr-TR","Turkish - Turkey",
"uk-UA","Ukrainian - Ukraine",
"ur-PK","Urdu - Pakistan",
"uz-Cyrl-UZ","Uzbek (Cyrillic) - Uzbekistan",
"uz-Latn-UZ","Uzbek (Latin) - Uzbekistan",
"vi-VN","Vietnamese - Vietnam" };

            List<SelectListItem> items = new List<SelectListItem>();

            for (int i = 0; i < values.Length; i = i + 2)
            {
                SelectListItem item = new SelectListItem();
                if (translate)
                    item.Text = "[!" + values[i + 1] + "!]";
                else
                    item.Text = values[i + 1];
                item.Value = values[i];
                item.Selected = selectedValue != null && values[i].Equals(selectedValue.ToString(), StringComparison.OrdinalIgnoreCase);
                items.Add(item);
            }

            return items;
        }
    }
}
